/* 
 * Ext GWT 2.2.4 - Ext for GWT 
 * Copyright(c) 2007-2010, Ext JS, LLC. 
 * licensing@extjs.com 
 *  
 * http://extjs.com/license 
 */
package masterjava.client.gxt.gxtcharts;

import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.extjs.gxt.charts.client.model.Legend;
import com.extjs.gxt.charts.client.model.ToolTip;
import com.extjs.gxt.charts.client.model.ToolTip.MouseStyle;
import com.extjs.gxt.charts.client.model.axis.Label;
import com.extjs.gxt.charts.client.model.axis.RadarAxis;
import com.extjs.gxt.charts.client.model.axis.XAxis;
import com.extjs.gxt.charts.client.model.axis.YAxis;
import com.extjs.gxt.charts.client.model.charts.*;
import com.extjs.gxt.charts.client.model.charts.BarChart.BarStyle;
import com.google.gwt.user.client.Random;

public class GxtChartModelsFactory {

    private static final int segments = 5;

    public static void setPieModel(Chart chart) {
        ChartModel cm = new ChartModel("Sales by Region",
                "font-size: 14px; font-family: Verdana; text-align: center;");
        cm.setBackgroundColour("#fffff5");
        Legend lg = new Legend(Legend.Position.RIGHT, true);
        lg.setPadding(10);
        cm.setLegend(lg);
        PieChart pie = new PieChart();
        pie.setAlpha(0.5f);
        pie.setNoLabels(true);
        pie.setTooltip("#label# $#val#M<br>#percent#");
        pie.setColours("#ff0000", "#00aa00", "#0000ff", "#ff9900", "#ff00ff");
        pie.addSlices(new PieChart.Slice(100, "AU", "Australia"));
        pie.addSlices(new PieChart.Slice(200, "US", "USA"));
        pie.addSlices(new PieChart.Slice(150, "JP", "Japan"));
        pie.addSlices(new PieChart.Slice(120, "DE", "Germany"));
        pie.addSlices(new PieChart.Slice(60, "UK", "United Kingdom"));
        cm.addChartConfig(pie);
        chart.setChartModel(cm);
    }


    public static void setAreaModel(Chart chart) {
        ChartModel cm = new ChartModel("Growth per Region", "font-size: 14px; font-family: Verdana;");
        cm.setBackgroundColour("#ffffff");
        XAxis xa = new XAxis();
        xa.setLabels("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D");
        cm.setXAxis(xa);
        AreaChart area1 = new AreaChart();
        area1.setFillAlpha(0.3f);
        area1.setColour("#ff0000");
        area1.setFillColour("#ff0000");
        for (int n = 0; n < 12; n++) {
            if (n % 3 != 0 && n != 11)
                area1.addNullValue();
            else
                area1.addValues(n * Random.nextDouble());
        }
        cm.addChartConfig(area1);
        AreaChart area2 = new AreaChart();
        area2.setFillAlpha(0.3f);
        area2.setColour("#00aa00");
        area2.setFillColour("#00aa00");
        int floor = Random.nextInt(3);
        double grade = (Random.nextInt(4) + 1) / 10.0;
        for (int n = 0; n < 12; n++) {
            if (n % 2 != 0 && n != 11)
                area2.addNullValue();
            else
                area2.addValues(n * grade + floor);
        }
        cm.addChartConfig(area2);
        chart.setChartModel(cm);
    }

    public static void setFilledBarModel(Chart chart) {
        ChartModel cm = new ChartModel("Sales by Month",
                "font-size: 16px; font-weight: bold; font-family: Verdana; color:#008800;");
        cm.setBackgroundColour("#eeffee");
        cm.setDecimalSeparatorComma(true);
        XAxis xa = new XAxis();
        xa.setLabels(TestData.getShortMonths(segments));
        xa.getLabels().setColour("#009900");
        xa.setGridColour("#eeffee");
        xa.setColour("#009900");
        cm.setXAxis(xa);
        YAxis ya = new YAxis();
        ya.setRange(5000, 20000);
        ya.setSteps(1000);
        ya.setGridColour("#eeffee");
        ya.setColour("#009900");
        cm.setYAxisLabelStyle(10, "#009900");
        cm.setYAxis(ya);
        FilledBarChart bchart = new FilledBarChart("#6666ff", "#000066");
        bchart.setTooltip("$#val#");
        for (int t = 0; t < segments; t++) {
            bchart.addValues(Random.nextInt(5000) + 10000);
        }
        cm.addChartConfig(bchart);
        chart.setChartModel(cm);
    }


    public static void setBarModel(Chart chart) {
        ChartModel cm = new ChartModel("Sales by Month 2007", "font-size: 14px; font-family: Verdana;");
        cm.setBackgroundColour("-1");
        XAxis xa = new XAxis();
        for (String m : TestData.getMonths()) {
            Label l = new Label(m, 45);
            l.setSize(10);
            l.setColour("#000000");
            xa.addLabels(l);
        }
        xa.setGridColour("-1");
        cm.setXAxis(xa);
        YAxis ya = new YAxis();
        ya.setSteps(16);
        ya.setMax(160);
        ya.setGridColour("#8888FF");
        cm.setYAxis(ya);
        BarChart bchart = new BarChart(BarStyle.GLASS);
        bchart.setColour("#FF00CC");
        bchart.setTooltip("$#val#");
        for (int t = 0; t < 12; t++) {
            if (t == segments - 1) {
                bchart.addBars(new BarChart.Bar(Random.nextInt(50) + 50, "#8888FF"));
            } else {
                bchart.addValues(Random.nextInt(50) + 50);
            }
        }
        cm.addChartConfig(bchart);
        chart.setChartModel(cm);
    }


    public static void setBar3DModel(Chart chart) {
        ChartModel cm = new ChartModel("Sales by Month 2008", "font-size: 14px; font-family: Verdana; color:#ffff00;");
        cm.setBackgroundColour("#000077");
        XAxis xa = new XAxis();
        xa.setLabels(TestData.getShortMonths(segments));
        xa.getLabels().setColour("#ffff00");
        xa.setGridColour("-1");
        xa.setColour("#aa5500");
        xa.setZDepth3D(5);
        cm.setXAxis(xa);
        YAxis ya = new YAxis();
        ya.setSteps(16);
        ya.setMax(160);
        ya.setGridColour("#000099");
        ya.setColour("#ffff00");
        cm.setYAxis(ya);
        cm.setYAxisLabelStyle(10, "#ffff00");
        BarChart bchart = new BarChart(BarStyle.THREED);
        bchart.setColour("#CC6600");
        bchart.setTooltip("$#val#");
        for (int t = 0; t < segments; t++) {
            bchart.addValues(Random.nextInt(50) + 50);
        }
        cm.addChartConfig(bchart);
        chart.setChartModel(cm);
    }


    public static void setRadarModel(Chart chart) {
        ChartModel cm = new ChartModel("Popularity", "font-size: 12px; text-align: left;");
        cm.setBackgroundColour("#f0f0f0");
        RadarAxis ra = new RadarAxis();
        ra.setMax(segments + 1);
        ra.setStroke(2);
        ra.setColour("#A1D4B5");
        ra.setGridColour("#C0DEBF");
        ra.setSpokeLabels("Ext", "Web", "Java", "AJAX", "PHP");
        cm.setRadarAxis(ra);
        AreaChart area = new AreaChart();
        area.setFillAlpha(0.3f);
        area.setColour("#ff9900");
        area.setFillColour("#ff6600");
        area.setLoop(true);
        area.addValues(segments);
        area.addValues(Random.nextInt(segments + 1));
        area.addValues(Random.nextInt(segments + 1));
        area.addValues(Random.nextInt(segments + 1));
        area.addValues(Random.nextInt(segments + 1));
        cm.addChartConfig(area);
        chart.setChartModel(cm);
    }

    public static void setHorizontalModel(Chart chart) {
        ChartModel cm = new ChartModel("Voted Best AJAX Framework",
                "font-size: 14px; font-family: Verdana; text-align: center;");
        XAxis xa = new XAxis();
        xa.setRange(0, 200, 50);
        cm.setXAxis(xa);
        YAxis ya = new YAxis();
        ya.addLabels("Ext", "Dojo", "jQuery", "YUI");
        ya.setOffset(true);
        cm.setYAxis(ya);
        HorizontalBarChart bchart = new HorizontalBarChart();
        bchart.setTooltip("#val# mph");
        bchart.addBars(new HorizontalBarChart.Bar(Random.nextInt(47) + 100, "#ffff00"));
        bchart.addBars(new HorizontalBarChart.Bar(Random.nextInt(44) + 100, "#0000ff"));
        bchart.addBars(new HorizontalBarChart.Bar(Random.nextInt(23) + 100, "#00ff00"));
        bchart.addBars(new HorizontalBarChart.Bar(Random.nextInt(50) + 150, "#ff0000"));
        cm.addChartConfig(bchart);
        cm.setTooltipStyle(new ToolTip(MouseStyle.FOLLOW));
        chart.setChartModel(cm);
    }

    public static void setCylinderModel(Chart chart) {
        ChartModel cm = new ChartModel("Licenses by Quarter 2008",
                "font-size: 14px; font-family: Verdana; text-align: center;");
        cm.setBackgroundColour("#ffffff");
        XAxis xa = new XAxis();
        xa.setLabels("Q1", "Q2", "Q3", "Q4");
        xa.setZDepth3D(5);
        xa.setTickHeight(4);
        xa.setOffset(true);
        xa.setColour("#909090");
        cm.setXAxis(xa);
        YAxis ya = new YAxis();
        ya.setSteps(16);
        ya.setMax(160);
        cm.setYAxis(ya);
        CylinderBarChart bchart = new CylinderBarChart();
        bchart.setColour("#440088");
        bchart.setAlpha(.8f);
        bchart.setTooltip("$#val#");
        for (int t = 0; t < 4; t++) {
            if ((t + 1) == (Math.ceil(segments / 3.0))) {
                bchart.addBars(new BarChart.Bar(Random.nextInt(50) + 50, "#aa88ff"));
            } else {
                bchart.addValues(Random.nextInt(50) + 50);
            }
        }
        cm.addChartConfig(bchart);
        chart.setChartModel(cm);
    }

    public static void setSketchModel(Chart chart) {
        ChartModel cm = new ChartModel("Smartest kid at school!", "font-size: 14px; font-family: Verdana;");
        cm.setBackgroundColour("#ffffff");
        XAxis xa = new XAxis();
        xa.setLabels("John", "Frank", "Mary", "Alec", "Mike", "James");
        cm.setXAxis(xa);
        SketchBarChart sketch = new SketchBarChart("#00aa00", "#009900", 6);
        sketch.setTooltip("#val# points");
        sketch.addValues(Random.nextInt(6) + 1, Random.nextInt(5) + 1, Random.nextInt(3) + 1);
        SketchBarChart.SketchBar skb = new SketchBarChart.SketchBar(Random.nextInt(5) + 5);
        skb.setColour("#6666ff");
        skb.setTooltip("Winner!<br>#val# points");
        sketch.addBars(skb);
        sketch.addValues(Random.nextInt(5) + 1, Random.nextInt(5) + 1);
        cm.addChartConfig(sketch);
        chart.setChartModel(cm);
    }
}